const knex = require('./knex');

class Recommend {
    constructor(props = 'recommender') {
        this.table = props;
      }
      /* 判断是否为新用户 */
      isNewUser(uid){
          return knex(this.table).select().where({"uid":uid}).first();
      }
      /* 插入推荐结果 */
      insert(uid, mids){
          return knex(this.table).insert({'uid':uid, 'rec':mids});
      }
      /* 老用户更新 */
      update(uid, mids){
          return knex(this.table).where({'uid':uid}).update({'rec':mids});
      }
      select(uid){
          return knex(this.table).select('rec').where({'uid':uid}).first();
      }
}

module.exports = new Recommend();